package demo1;


import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws Exception {
        //1.传统
        User user = new User();
        user.sayHello();

        //2.反射机制
        Class cls = Class.forName("demo1.User");
        Object obj = cls.newInstance();
        Method method = cls.getMethod("sayHello");
        method.invoke(obj);

        //3.Spring容器
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("demo1");
        User user1 = context.getBean(User.class);
        user1.sayHello();

    }
}
